package cn.weseal.cxf.ws.impl;

import cn.weseal.cxf.domain.Cat;
import cn.weseal.cxf.domain.User;
import cn.weseal.cxf.ws.HelloWorld;

import javax.jws.WebService;
import java.util.*;

/**
 * Created by Administrator on 2015/7/15.
 */
@WebService(endpointInterface = "cn.weseal.cxf.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
    static Map<User,List<Cat>> maps=new HashMap<User,List<Cat>>();
    static {
        List<Cat> cats1=new ArrayList<Cat>();
        cats1.add(new Cat(1,"red","benze"));
        cats1.add(new Cat(2,"black","宝马"));
        cats1.add(new Cat(3,"yellow","阿斯顿马丁"));
        User user1=new User("weseal",1,"13112312345","weseal11");
        maps.put(user1,cats1);

        List<Cat> cats2=new ArrayList<Cat>();
        cats2.add(new Cat(1,"red","宾利"));
        cats2.add(new Cat(2,"black","法拉利"));
        cats2.add(new Cat(3,"yellow","劳斯莱斯"));
        User user2=new User("qing",2,"77887788778","qing11");
        maps.put(user2,cats2);
        System.out.println(maps);
    }

    @Override
    public List<Cat> getCatsByUser(User u) {
        System.out.println("-------in this--------");
        List<Cat> cats= this.maps.get(u);
        System.out.println(cats);
        return cats;
    }

    @Override
    public String sayHello(String name) {
        return "Hello "+name+" now:"+new Date();
    }

    @Override
    public Map<String, Cat> getMaps() {
        Map<String,Cat> result=new HashMap<String,Cat>();
        int i=0;
        for(List<Cat> cats:maps.values()){
            for(Cat c:cats)
                result.put("第"+(++i)+"个",c);
        }

        return result;
    }
}
